<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Banner;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Facades\Cache;
class BannerController extends AdminController
{

    private $types = [
        0=>'PC版',
        1=>'手机版'
    ];
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Banner(), function (Grid $grid) {

            $grid->column('page','URL路徑');
            $grid->column('img','圖片(pc)')->image('','100','100');
            $grid->column('m_img','圖片(m)')->image('','100','100');
            $grid->column('href','鏈接');
            $grid->column('alt','圖片ALT');
            $grid->column('created_at');
            $grid->disableRowSelector();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableView();
            });

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Banner(), function (Show $show) {
            $show->field('id');
            $show->field('img');
            $show->field('href');
            $show->field('page');
            $show->field('alt');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Banner, function (Form $form) {

            $form->text('page', 'URL路徑')->required()->help(' 如：https://xxx.com/cate1 填入/cate1 表示該頁面的banner，首頁填入 / ');
            $form->image('img','圖片(pc)')->required()->autoUpload()->uniqueName();
            $form->image('m_img','圖片(m)')->autoUpload()->uniqueName();
            $form->text('href','鏈接');
            $form->text('alt','圖片ALT');


            $form->saved(function(){
                Cache::forget(config('global.cache.banner'));
            });

            $form->disableViewButton();
            $form->footer(function ($footer) {

                // 去掉`重置`按钮
                $footer->disableReset();

                // 去掉`查看`checkbox
                $footer->disableViewCheck();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
        });
    }
}
